package com.ruoyi.fitsculpt.domain;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Calendar;

import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import com.ruoyi.common.core.domain.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableField;

/**
 * 用户详细信息对象 easyfit_user_profiles
 *
 * @author metaee
 * @date 2025-02-27
 */
@ApiModel("用户详细信息对象")
public class EasyfitUserProfiles extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * 档案ID
     */
    @ApiModelProperty("档案ID")
    @Excel(name = "档案ID")
    private Long profileId;

    /**
     * 用户ID
     */
    @ApiModelProperty("用户ID")
    @Excel(name = "用户ID")
    private Long userId;

    /**
     * 性别（0未知 1男 2女）
     */
    @ApiModelProperty("性别")
    @Excel(name = "性别", readConverterExp = "0=未知,1=男,2=女")
    private String gender;

    /**
     * 出生日期
     */
    @ApiModelProperty("出生日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "出生日期", width = 30, dateFormat = "yyyy-MM-dd")
    private Date birthday;

    /**
     * 身高(cm)
     */
    @ApiModelProperty("身高(cm)")
    @Excel(name = "身高(cm)")
    private BigDecimal height;

    /**
     * 体重(kg)
     */
    @ApiModelProperty("体重(kg)")
    @Excel(name = "体重(kg)")
    private BigDecimal weight;

    /**
     * 运动频率 1:从不 2:偶尔 3:经常 4:每天
     */
    @ApiModelProperty("运动频率 1:从不 2:偶尔 3:经常 4:每天")
    @Excel(name = "运动频率 1:从不 2:偶尔 3:经常 4:每天")
    private Long exerciseFrequency;

    /**
     * 习惯运动时间
     */
    @ApiModelProperty("习惯运动时间")
    @Excel(name = "习惯运动时间")
    private String exerciseTime;

    /**
     * 每次运动时长(分钟)
     */
    @ApiModelProperty("每次运动时长(分钟)")
    @Excel(name = "每次运动时长(分钟)")
    private Long exerciseDuration;

    /**
     * 慢性疾病
     */
    @ApiModelProperty("慢性疾病")
    @Excel(name = "慢性疾病")
    private String chronicDiseases;

    /**
     * 饮食偏好
     */
    @ApiModelProperty("饮食偏好")
    @Excel(name = "饮食偏好")
    private String foodPreferences;

    /**
     * 过敏史
     */
    @ApiModelProperty("过敏史")
    @Excel(name = "过敏史")
    private String allergies;

    /** 关联的用户基本信息 */
    @TableField(exist = false)
    private EasyfitUsers user;

    /** BMI指数 */
    @TableField(exist = false)
    private BigDecimal bmi;

    /** 基础代谢率(BMR) */
    @TableField(exist = false)
    private BigDecimal basalMetabolicRate;

    /** 每日所需热量 */
    @TableField(exist = false)
    private BigDecimal dailyCaloriesNeeded;

    /** 活动等级 1:久坐不动 2:轻度活动 3:中度活动 4:重度活动 5:非常活跃 */
    @ApiModelProperty("活动等级")
    @Excel(name = "活动等级")
    private Long activityLevel;

    public Long getProfileId() {
        return profileId;
    }

    public void setProfileId(Long profileId) {
        this.profileId = profileId;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public BigDecimal getHeight() {
        return height;
    }

    public void setHeight(BigDecimal height) {
        this.height = height;
    }

    public BigDecimal getWeight() {
        return weight;
    }

    public void setWeight(BigDecimal weight) {
        this.weight = weight;
    }

    public Long getExerciseFrequency() {
        return exerciseFrequency;
    }

    public void setExerciseFrequency(Long exerciseFrequency) {
        this.exerciseFrequency = exerciseFrequency;
    }

    public String getExerciseTime() {
        return exerciseTime;
    }

    public void setExerciseTime(String exerciseTime) {
        this.exerciseTime = exerciseTime;
    }

    public Long getExerciseDuration() {
        return exerciseDuration;
    }

    public void setExerciseDuration(Long exerciseDuration) {
        this.exerciseDuration = exerciseDuration;
    }

    public String getChronicDiseases() {
        return chronicDiseases;
    }

    public void setChronicDiseases(String chronicDiseases) {
        this.chronicDiseases = chronicDiseases;
    }

    public String getFoodPreferences() {
        return foodPreferences;
    }

    public void setFoodPreferences(String foodPreferences) {
        this.foodPreferences = foodPreferences;
    }

    public String getAllergies() {
        return allergies;
    }

    public void setAllergies(String allergies) {
        this.allergies = allergies;
    }

    public EasyfitUsers getUser() {
        return user;
    }

    public void setUser(EasyfitUsers user) {
        this.user = user;
    }

    public BigDecimal getBmi() {
        return bmi;
    }

    public void setBmi(BigDecimal bmi) {
        this.bmi = bmi;
    }

    public BigDecimal getBasalMetabolicRate() {
        return basalMetabolicRate;
    }

    public void setBasalMetabolicRate(BigDecimal basalMetabolicRate) {
        this.basalMetabolicRate = basalMetabolicRate;
    }

    public BigDecimal getDailyCaloriesNeeded() {
        return dailyCaloriesNeeded;
    }

    public void setDailyCaloriesNeeded(BigDecimal dailyCaloriesNeeded) {
        this.dailyCaloriesNeeded = dailyCaloriesNeeded;
    }

    /**
     * 获取年龄
     * 
     * @return 年龄
     */
    public Integer getAge() {
        if (birthday == null) {
            return null;
        }
        Calendar cal = Calendar.getInstance();
        int yearNow = cal.get(Calendar.YEAR);
        int monthNow = cal.get(Calendar.MONTH);
        int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH);
        
        cal.setTime(birthday);
        int yearBirth = cal.get(Calendar.YEAR);
        int monthBirth = cal.get(Calendar.MONTH);
        int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);
        
        int age = yearNow - yearBirth;
        
        if (monthNow < monthBirth || (monthNow == monthBirth && dayOfMonthNow < dayOfMonthBirth)) {
            age--;
        }
        
        return age;
    }

    public Long getActivityLevel() {
        return activityLevel;
    }

    public void setActivityLevel(Long activityLevel) {
        this.activityLevel = activityLevel;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("profileId", getProfileId())
                .append("userId", getUserId())
                .append("gender", getGender())
                .append("birthday", getBirthday())
                .append("height", getHeight())
                .append("weight", getWeight())
                .append("exerciseFrequency", getExerciseFrequency())
                .append("exerciseTime", getExerciseTime())
                .append("exerciseDuration", getExerciseDuration())
                .append("chronicDiseases", getChronicDiseases())
                .append("foodPreferences", getFoodPreferences())
                .append("allergies", getAllergies())
                .append("user", getUser())
                .append("bmi", getBmi())
                .append("basalMetabolicRate", getBasalMetabolicRate())
                .append("dailyCaloriesNeeded", getDailyCaloriesNeeded())
                .append("activityLevel", getActivityLevel())
                .append("createTime", getCreateTime())
                .append("updateTime", getUpdateTime())
                .toString();
    }
}
